package com.niuxiaofa.newlaw.View;

import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.luck.picture.lib.tools.ToastUtils;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.ShareTool;
import com.niuxiaofa.newlaw.Tools.UIUtils;

/**
 * <p>文件描述：<p>
 * <p>作者：20200911A<p>
 * <p>创建时间：2021/2/4<p>
 * <p>更改时间：2021/2/4<p>
 * <p>版本号：1<p>
 */
public class ShareDialog {

    Activity activity;
    String url;
    String description;

    public void setDialog(Activity activity, String url, String description) {
        this.activity = activity;
        this.url = url;
        this.description = description;


        Dialog mCameraDialog = new Dialog(activity, R.style.BottomDialog);
        LinearLayout root = (LinearLayout) LayoutInflater.from(activity).inflate(
                R.layout.view_share, null);
        //初始化视图

        TextView cancel = root.findViewById(R.id.cancel);
        cancel.setOnClickListener(e -> {
            mCameraDialog.dismiss();
        });


        LinearLayout vx = root.findViewById(R.id.vx);
        LinearLayout qq = root.findViewById(R.id.qq);
        LinearLayout wb = root.findViewById(R.id.wb);
        LinearLayout pyq = root.findViewById(R.id.pyq);
        LinearLayout qzone = root.findViewById(R.id.qzone);
        LinearLayout copylink = root.findViewById(R.id.copylink);


        vx.setOnClickListener(e -> {
            ShareTool.shareVX(activity, "牛晓法","牛晓法",url,1);
        });
        qq.setOnClickListener(e -> {

            ShareTool.shareQQ(activity, "牛晓法", url,1);

        });
        wb.setOnClickListener(e -> {

            ShareTool.shareWB(activity, "牛晓法", url);

        });
        pyq.setOnClickListener(e -> {
            ShareTool.shareVX(activity, "牛晓法","牛晓法",url,3);
        });
        qzone.setOnClickListener(e -> {
                    ShareTool.shareQQ(activity, "牛晓法", url,2);

                }
        );
        copylink.setOnClickListener(e -> {
                    //获取剪贴板管理器：
                    ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                    // 创建普通字符型ClipData
                    ClipData mClipData = ClipData.newPlainText("Label", url);
                    // 将ClipData内容放到系统剪贴板里。
                    cm.setPrimaryClip(mClipData);
            ToastUtils.s(UIUtils.getActivity(),"复制成功");
                }
        );


        mCameraDialog.setContentView(root);
        Window dialogWindow = mCameraDialog.getWindow();
        dialogWindow.setGravity(Gravity.BOTTOM);
//        dialogWindow.setWindowAnimations(R.style.dialogstyle); // 添加动画
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        lp.x = 0; // 新位置X坐标
        lp.y = 0; // 新位置Y坐标
        lp.width = (int) activity.getResources().getDisplayMetrics().widthPixels; // 宽度
        root.measure(0, 0);
        lp.height = root.getMeasuredHeight();

        lp.alpha = 1f; // 透明度
        dialogWindow.setAttributes(lp);
        mCameraDialog.show();
    }

 

}
